//引入组件
import Register from '@/pages/Register';
import Login from '@/pages/Login';
import Search from '@/pages/Search';
import Detail from '@/pages/Detail';
import AddCartSuccess from '@/pages/AddCartSuccess';
import ShopCart from '@/pages/ShopCart';
import Trade from '@/pages/Trade';
import Pay from '@/pages/Pay';
import PaySuccess from '@/pages/PaySuccess';
import Center from '@/pages/Center';
//引入二级路由组件
import MyOrder from '@/pages/Center/myOrder';
import groupOrder from '@/pages/Center/groupOrder'

    export default 
        [
            {
                path:'/center',
                redirect:'/center/myorder',
                component:Center,
                meta:{show:true},
                //二级目录
                children:[
                    {
                        path:'myorder',
                        component:MyOrder,
                    },
                    {
                        path:'grouporder',
                        component:groupOrder,
                    },
                    
                ],
                
            },
            {
                path:'/paysuccess',
                component:PaySuccess,
                meta:{show:true}
            },
            {
                path:'/pay',
                component:Pay,
                meta:{show:true},
                //路由独享守卫
                beforeEnter: (to, from, next) => {
                    //如果是去交易页面，则必须是从购物车而来
                    if(from.path=='/trade'){
                        next();
                    }else{
                        //其他组件而来，停留当前
                        next(false);
                    }
                }
            },
            {
                path:'/trade',
                component:Trade,
                meta:{show:true},
                //路由独享守卫
                beforeEnter: (to, from, next) => {
                    //如果是去交易页面，则必须是从购物车而来
                    if(from.path=='/shopcart'){
                        next();
                    }else{
                        //其他组件而来，停留当前
                        next(false);
                    }
                }
            },
            {
                path:'/shopCart',
                component:ShopCart,
                meta:{show:true}
            },
            {
                path:'/addCartSuccess',
                name:'addCartSuccess',
                component:AddCartSuccess,
                meta:{show:true}
            },
            {
                path:'/detail/:skuid',
                component:Detail,
                meta:{show:true}
            },
            //路由懒加载引入home组件
            {
                path:'/home',
                component:()=> import('@/pages/Home'),
                meta:{show:true}
            },
            {
                path:'/register',
                component:Register,
                meta:{show:true}
            },
            {
                path:'/login',
                component:Login,
                meta:{show:false}
            },
            {
                path:'/search/:keyword?',
                component:Search,
                meta:{show:false},
                name:'search',
                // //1、布尔值写法:params
                // props:true
                // //2、对象写法：额外给路由组件传递一些props
                // props:{a:1,b:2}
                // //3、函数写法，可以params参数、query参数、通过props传递给路由组件
                props:($route)=>{
                    return {keyword:$route.params.keyword,k:$route.query.k};
                }
            },

            //重定向，在页面刚刷新时，访问/home，跳转到首页
            {
                path:'/',
                redirect:'/home'
            }
        ]